<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //99.94%
    var addBinary = function(a, b) {
        if(a == '0' && b == '0')return '0';
        let len1 = a.length, len2 = b.length;
        if(len1 < len2){
            a = '0'.repeat(len2-len1) + a;
        }else{
            b = '0'.repeat(len1-len2) + b;
        }
        a = '0' + a;
        b = '0' + b;
        let len = a.length;
        let sum = '';
        let flag = 0;
        for(let i=len-1; i>=0; i--){
            if(parseInt(a[i]) + parseInt(b[i]) == 0){
                if(flag == 0){
                    sum += '0'
                }else{
                    sum += '1';
                }
                flag = 0;
            }else if(parseInt(a[i]) + parseInt(b[i]) == 1){
                if(flag == 0){
                    sum += '1'
                }else{
                    sum += '0';
                    flag = 1;
                }
            }else if(parseInt(a[i]) + parseInt(b[i]) == 2){
                if(flag == 0){
                    sum += '0';
                }else{
                    sum += '1';
                }
                flag = 1;
            }
        }
        sum = sum.split('').reverse().join('');
        if(sum[0] == '0'){
            sum = sum.slice(1);
        }
        return sum;
    };
    let a = "11", b = "11";
    console.log(addBinary(a, b));
    
</script>
</html>